<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'doadd.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <% 	Connection con;
  		Statement sql;
  		ResultSet rs;
  		request.setCharacterEncoding("UTF-8");
  		String name=request.getParameter("name");
  		String tel=request.getParameter("tel");
  		String address=request.getParameter("address");
  		if(name==null||name.length()==0){
  			out.print("名字不能为空！");}
  		else{
  			try{	Class.forName("com.mysql.jdbc.Driver");
  				}
  			catch(Exception e){
  				out.println("需把MySQL数据库的JDBC-数据库驱动程序复制到JDK的扩展目录中");
  				}
  			try{
  				String uri="jdbc:mysql://localhost:3306/peopletext";
  				String user="root";
  				String password="kamui5201";
  				con=DriverManager.getConnection(uri,user,password);
  				sql=con.createStatement();
  				sql.executeUpdate("insert into pinfo(pname,ptel,pad) values('"+name+"','"+tel+"','"+address+"')");
  				con.close();
  				out.println("<script language=javascript>alert('添加成功！');window.location.href='index.jsp';</script>");
  				
  				}
  			catch(SQLException e){
  			out.println(e);
  				}
  				
  			}
  
  
  
  
  %>	
  	
   
  </body>
</html>
